package com.qiaofang.applet.service.property.service.mapstruct;

import com.qiaofang.applet.service.property.domain.Estate;
import com.qiaofang.applet.service.property.domain.EstateComment;
import com.qiaofang.applet.service.property.domain.EstateDetail;
import com.qiaofang.applet.service.property.service.dto.EstateCommentAddDto;
import com.qiaofang.applet.service.property.service.dto.EstateEditDto;
import org.bson.types.ObjectId;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;

import java.util.Date;

/**
 * @author: youqing.yang
 * @create: 2020/09/17 16:50
 **/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface EstateDetailMapper {

    EstateEditDto domainToEditDto(EstateDetail estateDetail);

    EstateDetail editDtoToDomain(EstateEditDto estateEditDto);

    EstateEditDto domainToDto(Estate estate);

    default EstateComment addDtoToAdmin(EstateCommentAddDto estateCommentAddDto) {
        if (estateCommentAddDto == null) {
            return null;
        }
        EstateComment estateComment = new EstateComment();

        estateComment.setId(ObjectId.get().toString());
        estateComment.setCommentContent(estateCommentAddDto.getCommentContent());
        estateComment.setOwnerName(estateCommentAddDto.getOwnerName());
        estateComment.setSort(estateCommentAddDto.getSort());
        estateComment.setCreateTime(new Date());
        return estateComment;
    }

}
